package com.qs.controller;


import com.qs.annotation.OperationLog;
import com.qs.pojo.dto.FeedbackDto;
import com.qs.pojo.dto.GoodsDto;
import com.qs.pojo.entity.Feedback;
import com.qs.response.Response;
import com.qs.service.IFeedbackService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 反馈表 前端控制器
 * </p>
 *
 * @author author
 * @since 2023-12-02
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/feedback")
@RequiredArgsConstructor
public class FeedbackController {

    private final IFeedbackService feedbackService;

    /**
     * 前台保存反馈数据
     * @param feedback
     * @return
     */
    @PostMapping("/save")
    public Response saveFeedback(@RequestBody Feedback feedback){
        log.info("前台保存反馈数据请求进来--------------------");
        feedbackService.save(feedback);
        return Response.success();
    }

    /**
     * 后台获取反馈分页数据
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/list/{pageNo}/{pageSize}")
    public Response listFeedback(@PathVariable Integer pageNo,
                                 @PathVariable Integer pageSize) {
        log.info("前台获取商品数据请求进来--------------------");
        Map<String,Object> feedbacks = feedbackService.listFeedback(pageNo, pageSize);
        return Response.success(feedbacks);
    }

    /**
     * 修改反馈
     * @param
     * @param
     * @param
     * @return
     */
    @PutMapping("/update")
    @OperationLog(operModul = "反馈管理-修改反馈",operDesc = "管理员修改反馈")
    public Response update(@RequestBody FeedbackDto feedbackDto) {
        log.info("修改反馈请求进来--------------------");
        feedbackService.updateByKey(feedbackDto);
        return Response.success();
    }

    /**
     * 反馈数据回显
     * @param
     * @param
     * @param
     * @return
     */
    @GetMapping("/getById/{id}")
    public Response echo(@PathVariable Integer id) {
        log.info("反馈数据回显请求进来--------------------");
        FeedbackDto feedbackDto =  feedbackService.echo(id);
        return Response.success(feedbackDto);
    }

    /**
     * 删除反馈
     * @param
     * @param
     * @param
     * @return
     */
    @DeleteMapping("/remove/{ids}")
    @OperationLog(operModul = "反馈管理-删除反馈",operDesc = "管理员删除反馈")
    public Response delete(@PathVariable List<Integer> ids) {
        log.info("删除反馈请求进来--------------------");
        feedbackService.removeBatchByIds(ids);
        return Response.success();
    }
}
